
// measure.js
var util = require('../../utils/util')

var app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        lstj: null,
        pageId: null,
        isfrom: null,
        zjx_Array: [//左肩型
            {
                id: 1,
                name: '正常肩'
            },
            {
                id: 51,
                name: '轻微溜肩'
            },
            {
                id: 2,
                name: '中度溜肩'
            },
            {
                id: 31,
                name: '严重溜肩'
            },
            {
                id: 45,
                name: '溜肩1.5'
            },
            {
                id: 46,
                name: '溜肩2.0'
            },
            {
                id: 54,
                name: '轻微耸肩'
            },
            {
                id: 4,
                name: '中度耸肩'
            },
            {
                id: 34,
                name: '严重耸肩'
            }
        ],
        yjx_Array: [//右肩型
            {
                id: 6,
                name: '正常肩'
            },
            {
                id: 52,
                name: '轻微溜肩'
            },
            {
                id: 7,
                name: '中度溜肩'
            },
            {
                id: 32,
                name: '严重溜肩'
            },
            {
                id: 47,
                name: '溜肩1.5'
            },
            {
                id: 48,
                name: '溜肩2.0'
            },
            {
                id: 53,
                name: '轻微耸肩'
            },
            {
                id: 9,
                name: '中度耸肩'
            },
            {
                id: 33,
                name: '严重耸肩'
            }
        ],
        dx_Array: [//肚型？
            {
                id: 15,
                name: '正常体'
            },
            {
                id: 16,
                name: '凸肚体'
            },
            {
                id: 136,
                name: '正常肚'
            }
        ],
        bx_Array: [//背型？
            {
                id: 11,
                name: '正常体'
            },
            {
                id: 12,
                name: '轻微驼背'
            },
            {
                id: 13,
                name: '驼背'
            },
            {
                id: 35,
                name: '中度驼背'
            },
            {
                id:36,
                name: '严重驼背'
            }
        ],
        sx_Array: [//臂型？
           {
               id: 17,
               name: '手臂靠前'
           },
           {
               id: 18,
               name: '轻微手臂靠后'
           },
           {
               id: 19,
               name: '手臂正常'
           },
           {
               id: 84,
               name: '严重手臂靠后'
           }
       ],
        tx_Array: [//臀型？
          {
              id: 20,
              name: '正常臀'
          },
          {
              id: 21,
              name: '平臀'
          },
          {
              id: 23,
              name: '凸臀'
          },
          {
              id: 25,
              name: '坠臀'
          }
      ],
        zjx_index: 0,//左肩
        yjx_index: 0,//右肩
        dx_index: 0, //肚子  
        bx_index: 0, //背
        sx_index: 0, //臂型
        tx_index: 0  //臀型
      
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
     //获取到用户的手机号
        this.setData({
            mohuanUser: app.globalData.mohuanUser,
            pageId: options
        })
        //获取从哪个页面点进来的，目前有两个
        this.setData({
            isfrom: options.isfrom
           
        })
        console.log("量体详情页面-------------->" + options.isfrom)
     
        // 页面初始化 options为页面跳转所带来的参数
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this;
        var url = 'https://www.magicmanufactory.com/c2mwebservice/api/v2/public/measure/distribution/' + this.data.mohuanUser.memberInfo.phoneNo
        console.log(url)
        wx.request({
            url: url,
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                // var measureId=res.goods[1].size.measureId;
                //获取到measureId，放到缓存中，用 key=“measureId”来获取
                var measureId = res.data.returnData[0].measureId;
                console.log("-----------------------measureID>"+measureId);
                try {
                    wx.setStorageSync('measureId', measureId)
                } catch (e) {
                }
                // 遍历所有数据，将name代表的province放到数组里
                res.data.returnData.forEach(function (element) {
                    element.measureDate = element.measureDate.split(" ")[0];
                })
                var pageId = that.data.pageId.pageId;
                that.setData({
                    lstj: res.data.returnData[pageId]
                })
              
                //左肩型
                var zjx_i = 0;
                that.data.zjx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].zjx) {
                        that.setData({
                            zjx_index: zjx_i
                        })
                    }
                    zjx_i++;
                })
                //右肩型
                var yjx_i = 0;
                that.data.yjx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].yjx) {
                        that.setData({
                            yjx_index: yjx_i
                        })
                    }
                    yjx_i++;
                })
                //肚型
                var dx_i = 0;
                that.data.dx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].dx) {
                        that.setData({
                            dx_index: dx_i
                        })
                    }
                    dx_i++;
                })
                //背
                var bx_i = 0;
                that.data.bx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].bx) {
                        that.setData({
                           bx_index: bx_i
                        })
                    }
                    bx_i++;
                })
                //手臂
                var sx_i = 0;
                that.data.sx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].sx) {
                        that.setData({
                            sx_index: sx_i
                        })
                    }
                   sx_i++;
                })
                //屁股
                var tx_i = 0;
                that.data.tx_Array.forEach(function (element) {
                    if (element.id == res.data.returnData[pageId].tx) {
                        that.setData({
                            tx_index: tx_i
                        })
                    }
                    tx_i++;
                })

            }
        })

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    buttonclick:function(){
       wx.navigateBack({
           
       })
        // wx.navigateTo({
        //   url: '../productInfo/productInfo',
        // })
      
     
    }
})